package br.ledtec.hardware.fetin2014.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class IntensitySliderPanel extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4466743932818933260L;
	
	private JSlider intensitySlider;
	private JLabel intensityLabel;
	
	private GridBagConstraints intensitySliderGridBagConstraints;
	private GridBagConstraints intensityLabelGridBagConstraints;
	
	private ChangeListener intensity;
	private IntensitySliderPanelListener intensitySliderPanelListener;
	
	public IntensitySliderPanel() {
		
		initialize();
	}

	private void initialize() {
		setLayout(new GridBagLayout());
		add(getIntensityLabel(), getIntensityLabelGridBagConstraints());
		add(getIntensitySlider(), getIntensitySliderGridBagConstraints());		
	}
	
	public JSlider getIntensitySlider() {
		if(intensitySlider == null)
		{
			intensitySlider = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
//			intensitySlider.setSize(10, 300);
			intensitySlider.setMajorTickSpacing(25);
			intensitySlider.setMinorTickSpacing(5);
			intensitySlider.setPaintTicks(true);
			intensitySlider.setPaintLabels(true);
			intensitySlider.addChangeListener(new ChangeListener() {
				
				@Override
				public void stateChanged(ChangeEvent e) {
					intensitySliderPanelListener.intensityPerformed();
//					sendIntensity();					
				}
			});
		}
		return intensitySlider;
	}
	
	public JLabel getIntensityLabel() {
		if(intensityLabel == null)
		{
			intensityLabel = new JLabel();
			intensityLabel.setText("Intensidade");
		}
		return intensityLabel;
	}
	
	public void addIntensitySliderPanelListener(
			IntensitySliderPanelListener intensitySliderPanelListener) {
		this.intensitySliderPanelListener = intensitySliderPanelListener;
	}	

	public GridBagConstraints getIntensitySliderGridBagConstraints() {
		if(intensitySliderGridBagConstraints == null) {
			intensitySliderGridBagConstraints = new GridBagConstraints();
			intensitySliderGridBagConstraints.gridx = 0;
			intensitySliderGridBagConstraints.gridy = 1;
			intensitySliderGridBagConstraints.insets = new Insets(2, 2, 2, 2);
			intensitySliderGridBagConstraints.anchor = new GridBagConstraints().CENTER;
		}
		return intensitySliderGridBagConstraints;
	}

	public GridBagConstraints getIntensityLabelGridBagConstraints() {
		if(intensityLabelGridBagConstraints == null) {
			intensityLabelGridBagConstraints = new GridBagConstraints();
			intensityLabelGridBagConstraints.gridx = 0;
			intensityLabelGridBagConstraints.gridy = 0;
			intensityLabelGridBagConstraints.insets = new Insets(2, 2, 2, 2);
			intensityLabelGridBagConstraints.anchor = new GridBagConstraints().CENTER;
		}
		return intensityLabelGridBagConstraints;
	}

	public ChangeListener getIntensity() {
		return intensity;
	}

}












